<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="/static/layui/css/layui.css">
  <title>Document</title>
  <style>
    .layui-container {
      margin-top: 20px;
    }
  </style>
</head>

<body>
  <div>
    <span class="layui-breadcrumb">
      <a href="/dashboard">仪表盘</a>
      <a><cite>商品列表</cite></a>
    </span>
  </div>

  <div class="layui-container">
    <a type="button" class="layui-btn layui-btn-lg layui-btn-warm" href="/additem"><i
        class="layui-icon layui-icon-add-circle-fine"></i>添加商品</a>
    <table class="layui-table">
      <colgroup>
        <col width="170">
        <col width="100">
        <col width="100">
        <col width="200">
        <col width="100">
        <col>
        <col width="200">
        <col width="200">
      </colgroup>
      <thead>
        <tr>
          <th>商品名称</th>
          <th>商品价格</th>
          <th>库存</th>
          <th>商品介绍</th>
          <th>商品状态</th>
          <th>预览图</th>
          <th>商品详情</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <% for(let i=0; i< result.length; i++) {%>
          <tr>
            <td>
              <%= result[i].itemName%>
            </td>
            <td>
              <%= result[i].itemPrice%>
            </td>
            <td>
              <%= result[i].itemStore%>
            </td>
            <td title="<%=result[i].itemIntro%>">
              <%= result[i].itemIntro ? (result[i].itemIntro.length> 10 ? result[i].itemIntro.substr(0,10)+'...' :
                result[i].itemIntro) : '暂无描述'%>
            </td>
            <td>
              <%= result[i].isSale ? '已下架' : '已上架' %>
            </td>
            <td>
              <img
                src="<%= result[i].itemThumb ? result[i].itemThumb : 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.hhhtrc.com%2Fuploads%2Fallimg%2F210203%2F16323C159-0.jpg'%>"
                alt="">

            </td>
            <td title="<%= result[i].content%>">
              <%= result[i].content ? (result[i].content.length> 10 ? result[i].content.substr(0,10)+'...' :
                result[i].content) : '暂无商品详情'%>
            </td>
            <td><button type="button" class="layui-btn layui-btn-xs layui-btn-normal layui-btn-radius"><i
                  class="layui-icon">&#xe60a;</i>编辑</button>
              <button type="button" class="layui-btn layui-btn-xs layui-btn-danger layui-btn-radius"><i
                  class="layui-icon"></i> 删除</button>
            </td>
          </tr>
          <% } %>
      </tbody>
    </table>
    <div id="test1"></div>
  </div>
  <script src="/static/layui/layui.js"></script>
  <script>
    layui.use(['laypage'], function () {
      //实例化分页模块
      var laypage = layui.laypage;

      //执行一个laypage实例
      laypage.render({
        elem: 'test1',
        limit: 4,
        limits: [5, 10, 15, 20, 25],
        count: 20, //数据总数，从服务端得到
        jump: function (obj, first) {
          //obj包含了当前分页的所有参数
          
          //首次不执行
          if (!first) {
            location.href = '/itemList?page=' + obj.curr + "&pageSize=" + obj.limit;
          }
        }
      });
    })
  </script>
</body>

</html>